//
//  SYStatus.swift
//  SYWeibo
//
//  Created by Saya on 16/4/11.
//  Copyright © 2016年 黄金果. All rights reserved.
//

import UIKit

class SYStatus: NSObject {
    ///content文案
    var text:String?
    ///微博id
    var id:Int64 = 0
    ///创建微博时间
    var created_at :String?
    ///微博来源
    var source :String?
    ///用户信息
    var user:SYUserDataCellModel?
    
    ///转发
    var reposts_count:Int = 0
    ///评论
    var comments_count:Int = 0
    ///赞
    var attitudes_count:Int = 0
    
    ///转发微博
    var retweeted_status:SYStatus?
    ///图片
    var pic_urls:[SYPictureModel]?
    
    
    init(dict:[String:AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    //处理一下user
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            guard let userDict = value as? [String:AnyObject] else{
                print("数据错误,不为字典")
                return
            }
            let userModel = SYUserDataCellModel(dict: userDict)
            self.user = userModel
            return
        }
        
        if key == "retweeted_status"{
            guard let tempRetweet = value as? [String:AnyObject] else {
                print("数据错误,不为字典")
                return
            }
            
            let retweet:SYStatus = SYStatus(dict: tempRetweet)
            self.retweeted_status = retweet
            return
        }
        
        if key == "pic_urls"{
            guard let tempPicArray = value as? [[String:String]] else {
                print("数据错误,不为字典")
                return
            }
//            print(tempPicArray)
//            print(value)
            var tempPic:[SYPictureModel] = [SYPictureModel]()
            for v in tempPicArray{
                let picModel = SYPictureModel(dict: v)
                tempPic.append(picModel)
            }
//            print(tempPic)
            self.pic_urls = tempPic
            return
        }
        
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    override var description: String {
        let keys = ["text","id","created_at","source","user"]
        let dict = self.dictionaryWithValuesForKeys(keys)
        return dict.description
    }

}
